package com.lt.eurekaconsumerribbon.controller;

import com.lt.dto.UserDto;
import com.lt.vo.ResultEntity;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping("/user/list")
    @HystrixCommand(fallbackMethod = "getUserListError")
    public ResultEntity getUserList( UserDto userDto){
        HttpEntity httpEntity = new HttpEntity(userDto);
        ResultEntity body = restTemplate.postForEntity("http://EUREKA-PRODUCER/user/list", httpEntity, ResultEntity.class).getBody();
        return  body;
    }

    public ResultEntity getUserListError(UserDto userDto){
        return ResultEntity.error("10001","服务器异常...");
    }

}
